package com.pai4j.pgc.dao;

import com.pai4j.pgc.entity.CreatorEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * 创作者DAO接口
 *
 * @author: CYM-pai
 * @date: 2025/11/01
 */
@Repository
public interface ICreatorDAO extends JpaRepository<CreatorEntity, Long>, JpaSpecificationExecutor<CreatorEntity> {
    
    /**
     * 根据用户ID查询创作者
     */
    Optional<CreatorEntity> findByUserId(String userId);
    
    /**
     * 根据用户ID和删除标识查询创作者
     */
    Optional<CreatorEntity> findByUserIdAndDeleteFlag(String userId, Integer deleteFlag);
    
    /**
     * 根据状态和删除标识分页查询
     */
    Page<CreatorEntity> findByStatusAndDeleteFlag(Integer status, Integer deleteFlag, Pageable pageable);
    
    /**
     * 统计指定状态的创作者数量
     */
    Long countByStatusAndDeleteFlag(Integer status, Integer deleteFlag);
    
    /**
     * 按经验值降序查询创作者排行（用于排行榜）
     */
    Page<CreatorEntity> findByDeleteFlagOrderByExperiencePointsDesc(Integer deleteFlag, Pageable pageable);
    
    /**
     * 根据等级和删除标识分页查询
     */
    Page<CreatorEntity> findByLevelAndDeleteFlag(Integer level, Integer deleteFlag, Pageable pageable);
}

